#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project  : seleniumGitee
# @File     : test_login_page.py
# @Author   : WanLiWei
# @Time     : 2021/7/1 23:12
# 引用selenium中的webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By
class PageLogin():
    """登录页面"""

    def __init__(self, driver):
        self.time = 10
        # 控制浏览器的driver
        self.driver = driver
        self.url = "http://192.168.4.138/ecshop/admin/"
        # 定义定位器
        self.login_username_loc = (By.NAME, "username")
        self.login_password_loc = (By.NAME, "password")
        self.login_button_loc = (By.CLASS_NAME, "button")

    def open(self):
        # 打开url
        self.driver.get(self.url)
        # 设置隐式等待
        self.driver.implicitly_wait(self.time)

    def login_username(self, username):
        # 用户名输入框
        self.driver.find_element(*self.login_username_loc).clear()
        self.driver.find_element(*self.login_username_loc).send_keys(username)

    def login_password(self, password):
        # 密码输入框
        self.driver.find_element(*self.login_password_loc).clear()
        self.driver.find_element(*self.login_password_loc).send_keys(password)

    def login_button(self):
        # 登录按钮
        self.driver.find_element(*self.login_button_loc).click()

    def login(self, username, password):
        # 登陆操作
        self.open()
        self.login_username(username)
        self.login_password(password)
        self.login_button()

